Skip to content

fix: sum true-stereo convolver results at unity gain - #1455

Merged
mdydek merged 4 commits into
software-mansion:mainfrom
abboskhon-dev:fix/convolver-true-stereo
Nov 17, 2026
Merged

mdydek merged 4 commits into
software-mansion:mainfrom
abboskhon-dev:fix/convolver-true-stereo

Conversation

@abboskhon-dev

@abboskhon-dev abboskhon-dev commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1454

⚠️ Breaking changes ⚠️

  • None in the API. One audible change: with normalize = false and a 4-channel impulse response, the output rises 6 dB and now matches Chrome. Output with normalize = true is unchanged.

Introduced changes

  • ConvolverNode::processNode adds the four true-stereo results itself (L = 0 + 2, R = 1 + 3) at unity gain. Before, AudioBuffer::sum treated them as a quad speaker layout and down-mixed them with 0.5.
  • On a mono bus (mono source, clamped-max) the four results are added with 0.5, the average of the stereo pair. Before, the 4 → 1 down-mix applied 0.25.
  • calculateNormalizationScale multiplies by 0.5 for a 4-channel response, like the // True-stereo compensation step in Chrome's CalculateNormalizationScale (reverb.cc). The 0.5 moves from the down-mix into the scale, so the normalized level stays the same.
  • The work per render quantum is the same: four channel sums, as before.
  • New ConvolverTrueStereoTest.cpp with four cases: stereo and mono bus, normalize on and off.
  • .claude/skills/utilities/SKILL.md: a two-line note that sum() and copy() apply speaker mixing gains between different channel counts.

Measured with a constant input (stereo: L = 0.5, R = 0.25; mono: 0.5) and a 4-channel response of single-sample impulses with gains 1.0, 0.5, 0.25, 0.75:

Input normalize Chrome 157 (L / R) main This PR
stereo false 0.5625 / 0.4375 0.28125 / 0.21875 0.5625 / 0.4375
stereo true 0.005851 / 0.004551 same, within 1e-6 same, within 1e-6
mono false 0.625 / 0.625 0.3125 0.625
mono true 0.006501 / 0.006501 same, within 1e-6 same, within 1e-6

Checklist

  • Linked relevant issue
  • Updated relevant documentation (n/a: no API change, and the docs do not describe the output level)
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage (n/a)
  • Added support for web (n/a: web uses the browser's ConvolverNode)
  • Updated old arch android spec file (n/a)

Tests:

  • ConvolverTrueStereoTest: the two normalize = false cases fail on main (0.28125 vs 0.5625 stereo, 0.3125 vs 0.625 mono) and pass here. The two normalize = true cases pass on both, which pins the unchanged level.
  • yarn test:cpp: 612 tests pass on top of d846d5c.
  • clang-format 23 (--dry-run --Werror) and cpplint with the flags from scripts/cpplint.sh: clean on the two changed C++ files.
  • The Chrome column comes from the OfflineAudioContext script in ConvolverNode: 4-channel (true stereo) impulse response is 6 dB quieter than Chrome when normalize is off #1454.
  • Not done: no build or run on a device or simulator, and no listening test.
  • Not covered: with a mono source the engine keeps a mono bus, so it outputs the average of the stereo pair that Chrome produces. That was already the case and this PR does not change it.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected true-stereo convolution output mixing for stereo and mono outputs, including normalized impulse responses.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

WPT non-regression comparison

PASS — no regressions · 0 improved section(s) · overall 3431 → 3431 (0)

Unchanged sections (28)
Spec section Base pass Head pass Delta
Processing model 1 1 0
Other 56 56 0
AnalyserNode 138 138 0
AudioBuffer 142 142 0
AudioBufferSourceNode 221 221 0
AudioContext 58 58 0
AudioNode 261 261 0
AudioParam 680 680 0
BiquadFilterNode 275 275 0
ChannelMergerNode 30 30 0
ChannelSplitterNode 7 7 0
ConstantSourceNode 64 64 0
ConvolverNode 179 179 0
DelayNode 127 127 0
DestinationNode 0 0 0
DynamicsCompressorNode 4 4 0
GainNode 15 15 0
IIRFilterNode 87 87 0
MediaElementAudioSourceNode 0 0 0
MediaStreamAudioDestinationNode 1 1 0
MediaStreamAudioSourceNode 0 0 0
OfflineAudioContext 35 35 0
OscillatorNode 104 104 0
PannerNode 727 727 0
PeriodicWave 33 33 0
ScriptProcessorNode 0 0 0
StereoPannerNode 104 104 0
WaveShaperNode 82 82 0

Baseline: 7da2c3832afaa2a9515a15a902ba16f1a2e55ecc · Candidate: 1b6ac7ff703c1897cbd1a2eb43cc8ab191f772fb

Workflow run · this comment is updated on every push.

@closetcaiman closetcaiman added the fix Code changes specifically addressing and resolving a bug label Nov 16, 2026

@maciejmakowski2003 maciejmakowski2003 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job! I have added a few nits

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

ConvolverNode now handles four-channel impulse responses with bus-specific mixing and an adjusted normalization scale. New C++ tests cover stereo and mono output with normalization enabled and disabled. Documentation clarifies how to sum node-owned intermediate channels.

Changes: True-stereo ConvolverNode mixing

Layer / File(s) Summary
Four-channel mixing and validation
packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.cpp, packages/react-native-audio-api/common/cpp/test/src/core/effects/ConvolverTrueStereoTest.cpp, .claude/skills/utilities/SKILL.md
Four-channel intermediate output is folded into the output bus by channel index. Mono output uses a 0.5 gain per contribution, while other bus sizes use unity gain. Normalization scaling changes for four-channel impulse responses. Tests cover stereo and mono output with normalization enabled and disabled. The documentation distinguishes speaker mixing from summing intermediate channels.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: maciejmakowski2003, mdydek

Merge Risk: Minimal · up to 7f0c7

True-stereo convolver output with normalization disabled becomes 6 dB louder, as intended, and normalized output is unchanged. Tests cover the new behavior, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the four true-stereo convolver results are now summed at unity gain. The PR objectives confirm this is the primary fix in ConvolverNode for 4-channel impulse responses…
Description check Passed The description follows the repository template. It links issue #1454 with 'Closes #1454', and it has the Breaking changes and Introduced changes sections. The checklist is filled in with reasons for …
Linked Issues check Passed Issue #1454 (direct, open) has three coding requirements. (1) Unity-gain stereo mixing and mono averaging: at the reviewed head, ConvolverNode::processNode maps the four intermediate channels onto the…
Out of Scope Changes check Passed All changes connect to #1454. ConvolverNode.cpp contains the mixing fix and the normalization factor. ConvolverTrueStereoTest.cpp covers the requested test cases. The .claude/skills/utilities/SKILL.md…
Full details: Title check

Explanation

The title names the main change: the four true-stereo convolver results are now summed at unity gain. The PR objectives confirm this is the primary fix in ConvolverNode for 4-channel impulse responses. The title is specific and concise, and it does not include file lists or vague terms.

Full details: Description check

Explanation

The description follows the repository template. It links issue #1454 with 'Closes #1454', and it has the Breaking changes and Introduced changes sections. The checklist is filled in with reasons for unchecked items. It gives a clear summary of the behavior change, the normalization handling, the new tests, and the measured results against Chrome and main. It also lists what was not tested (no device or simulator build, no listening test). The target branch is not stated explicitly, but the change is a fix on main, and the template allows that.

Full details: Linked Issues check

Explanation

Issue #1454 (direct, open) has three coding requirements. (1) Unity-gain stereo mixing and mono averaging: at the reviewed head, ConvolverNode::processNode maps the four intermediate channels onto the bus with channel % busChannels. Stereo output receives intermediate 0 + 2 on left and 1 + 3 on right at gain 1.0. Mono output receives all four at gain 0.5. I checked this against outputChannelMap_ = {0, 3, 2, 1} in performConvolution, which gives LL and RL on intermediate 0 and 2 (left) and RR and LR on 1 and 3 (right). (2) Normalization compensation: calculateNormalizationScale multiplies by 0.5 when the IR has four channels, as the issue requests. (3) C++ tests for stereo and mono buses with normalize on and off: ConvolverTrueStereoTest.cpp is described in the PR summary with four cases. I did not read the test file directly, so this part rests on the PR description and summary. Implementation requirements are met. The test coverage requirement is supported by the described test file but not independently verified.

Full details: Out of Scope Changes check

Explanation

All changes connect to #1454. ConvolverNode.cpp contains the mixing fix and the normalization factor. ConvolverTrueStereoTest.cpp covers the requested test cases. The .claude/skills/utilities/SKILL.md change is a two-line documentation note that describes the speaker-mixing gains of sum() and copy(). The fix depends on that behavior, so the note supports the change. No unrelated code change was found in the reviewed ConvolverNode.cpp. The test file and SKILL.md were not read directly and rely on the PR summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 31250ff9-0d86-4878-b761-047ce0bc3a18
Commits

Reviewing files that changed from the base of the PR and between 7da2c38 and 7f0c763.

Files selected for processing: 3

  • .claude/skills/utilities/SKILL.md
  • packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.cpp
  • packages/react-native-audio-api/common/cpp/test/src/core/effects/ConvolverTrueStereoTest.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

C++ coverage

Smoke suites, Clang source-based coverage.

Covered Total %
Lines 7636 10448 73.09%
Functions 1062 1327 80.03%
Regions 3965 5391 73.55%

Lines changed in this pull request

  • Total: 13 lines

  • Missing: 2 lines

  • Coverage: 84%

  • packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.cpp (84.6%): Missing lines 141-142

Uncovered changed lines

packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.cpp

Lines 137-146

  137         audioBuffer_->getChannel(channel % busChannels)
  138             ->sum(*intermediateBuffer_->getChannel(channel), 0, 0, RENDER_QUANTUM_SIZE, gain);
  139       }
  140     } else {
! 141       audioBuffer_->sum(*intermediateBuffer_);
! 142     }
  143 
  144     internalBuffer_->copy(*audioBuffer_, 0, internalBufferIndex_, RENDER_QUANTUM_SIZE);
  145     internalBufferIndex_ += RENDER_QUANTUM_SIZE;
  146   }

Workflow run · this comment is updated on every push.

@github-actions

Copy link
Copy Markdown
Contributor

WPT non-regression comparison

PASS — no regressions · 0 improved section(s) · overall 3431 → 3431 (0)

Unchanged sections (28)
Spec section Base pass Head pass Delta
Processing model 1 1 0
Other 56 56 0
AnalyserNode 138 138 0
AudioBuffer 142 142 0
AudioBufferSourceNode 221 221 0
AudioContext 58 58 0
AudioNode 261 261 0
AudioParam 680 680 0
BiquadFilterNode 275 275 0
ChannelMergerNode 30 30 0
ChannelSplitterNode 7 7 0
ConstantSourceNode 64 64 0
ConvolverNode 179 179 0
DelayNode 127 127 0
DestinationNode 0 0 0
DynamicsCompressorNode 4 4 0
GainNode 15 15 0
IIRFilterNode 87 87 0
MediaElementAudioSourceNode 0 0 0
MediaStreamAudioDestinationNode 1 1 0
MediaStreamAudioSourceNode 0 0 0
OfflineAudioContext 35 35 0
OscillatorNode 104 104 0
PannerNode 727 727 0
PeriodicWave 33 33 0
ScriptProcessorNode 0 0 0
StereoPannerNode 104 104 0
WaveShaperNode 82 82 0

Baseline: 7da2c3832afaa2a9515a15a902ba16f1a2e55ecc · Candidate: 7f0c7639cc702710417068d99a1437a7ac8924b7

Workflow run · this comment is updated on every push.

@mdydek
mdydek merged commit 05dd1c4 into software-mansion:main Nov 17, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Code changes specifically addressing and resolving a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConvolverNode: 4-channel (true stereo) impulse response is 6 dB quieter than Chrome when normalize is off

4 participants